package com.ruoyi.aftserv.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.aftserv.domain.ManageGradeClass;
import com.ruoyi.aftserv.service.IManageGradeClassService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班级Controller
 * 
 * @author 张艳羽
 * @date 2024-08-19
 */
@Controller
@RequestMapping("/aftserv/gradeclass")
public class ManageGradeClassController extends BaseController
{
    private String prefix = "aftserv/gradeclass";

    @Autowired
    private IManageGradeClassService manageGradeClassService;

    @RequiresPermissions("aftserv:gradeclass:view")
    @GetMapping()
    public String gradeclass()
    {
        return prefix + "/gradeclass";
    }

    /**
     * 查询班级列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ManageGradeClass manageGradeClass)
    {
        startPage();
        List<ManageGradeClass> list = manageGradeClassService.selectManageGradeClassList(manageGradeClass);
        return getDataTable(list);
    }

    /**
     * 导出班级列表
     */
    @Log(title = "班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ManageGradeClass manageGradeClass)
    {
        List<ManageGradeClass> list = manageGradeClassService.selectManageGradeClassList(manageGradeClass);
        ExcelUtil<ManageGradeClass> util = new ExcelUtil<ManageGradeClass>(ManageGradeClass.class);
        return util.exportExcel(list, "班级数据");
    }

    /**
     * 新增班级
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存班级
     */
    @RequiresPermissions("aftserv:gradeclass:add")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ManageGradeClass manageGradeClass)
    {
        return toAjax(manageGradeClassService.insertManageGradeClass(manageGradeClass));
    }

    /**
     * 修改班级
     */
    @RequiresPermissions("aftserv:gradeclass:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ManageGradeClass manageGradeClass = manageGradeClassService.selectManageGradeClassById(id);
        mmap.put("manageGradeClass", manageGradeClass);
        return prefix + "/edit";
    }

    /**
     * 修改保存班级
     */
    @RequiresPermissions("aftserv:gradeclass:edit")
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ManageGradeClass manageGradeClass)
    {
        return toAjax(manageGradeClassService.updateManageGradeClass(manageGradeClass));
    }

    /**
     * 删除班级
     */
    @RequiresPermissions("aftserv:gradeclass:remove")
    @Log(title = "班级", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(manageGradeClassService.deleteManageGradeClassByIds(ids));
    }

    /**
     * 校验
     */
    @PostMapping("/checkClassCodeUnique")
    @ResponseBody
    public boolean checkClassCodeUnique(ManageGradeClass gradeClass)
    {
        return this.manageGradeClassService.checkClassCodeUnique(gradeClass);
    }
}
